package com.yic.module.mes.dal.mysql.moroute;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.mes.dal.dataobject.moroute.MoRouteDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.mes.controller.admin.moroute.vo.*;

/**
 * 工单工艺路线 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface MoRouteMapper extends BaseMapperX<MoRouteDO> {

    default PageResult<MoRouteDO> selectPage(MoRoutePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MoRouteDO>()
                .eqIfPresent(MoRouteDO::getMoId, reqVO.getMoId())
                .eqIfPresent(MoRouteDO::getMoCode, reqVO.getMoCode())
                .eqIfPresent(MoRouteDO::getRouteId, reqVO.getRouteId())
                .eqIfPresent(MoRouteDO::getProcessId, reqVO.getProcessId())
                .eqIfPresent(MoRouteDO::getNextProcessId, reqVO.getNextProcessId())
                .eqIfPresent(MoRouteDO::getSubsequence, reqVO.getSubsequence())
                .eqIfPresent(MoRouteDO::getLink, reqVO.getLink())
                .eqIfPresent(MoRouteDO::getMainProcess, reqVO.getMainProcess())
                .betweenIfPresent(MoRouteDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MoRouteDO::getId));
    }

    default List<MoRouteDO> selectList(MoRouteExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MoRouteDO>()
                .eqIfPresent(MoRouteDO::getMoId, reqVO.getMoId())
                .eqIfPresent(MoRouteDO::getMoCode, reqVO.getMoCode())
                .eqIfPresent(MoRouteDO::getRouteId, reqVO.getRouteId())
                .eqIfPresent(MoRouteDO::getProcessId, reqVO.getProcessId())
                .eqIfPresent(MoRouteDO::getNextProcessId, reqVO.getNextProcessId())
                .eqIfPresent(MoRouteDO::getSubsequence, reqVO.getSubsequence())
                .eqIfPresent(MoRouteDO::getLink, reqVO.getLink())
                .eqIfPresent(MoRouteDO::getMainProcess, reqVO.getMainProcess())
                .betweenIfPresent(MoRouteDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MoRouteDO::getId));
    }

    default int deleteByMoId(Long id) {
        return delete(new LambdaQueryWrapperX<MoRouteDO>()
                .eq(MoRouteDO::getMoId, id));
    }

    default List<MoRouteDO> selectListByMoId(Long id) {
        return selectList(new LambdaQueryWrapperX<MoRouteDO>()
                .eq(MoRouteDO::getMoId, id));
    }

    default MoRouteDO selectOneByProcessId(Long processId) {
        return selectOne(new LambdaQueryWrapperX<MoRouteDO>()
                .eq(MoRouteDO::getProcessId, processId)
                .last("limit 1"));
    }
}
